<?php
/**
 * Comparator
 *
 * Comparison operators, as their name implies, allow you to compare
 * two values.
 *
 * @author  Badrus Said <badrus.said@gmail.com>
 * @since   gop1.0
 */
final class gop_Comparator extends gop_Base {
    const ID = "===", NI = "!==", EQ = "==", NE = "!=", LT = "<", LE = "<=", GT = ">", GE = ">=";
    public function execute(gop_Base $_caller = null) {
        if ($this->getReturn()) return;
        $this->setCaller(null);
        $this->getContext()->getCallee($this->le)->execute($this);
        $le = $this->getResult();
        $this->getContext()->getCallee($this->re)->execute($this);
        $re = $this->getResult();
        $rs = false;
        switch($this->op) {
            case self::ID: $rs = $le ===$re; break;
            case self::NI: $rs = $le !==$re; break;
            case self::EQ: $rs = $le == $re; break;
            case self::NE: $rs = $le != $re; break;
            case self::LT: $rs = $le  < $re; break;
            case self::LE: $rs = $le <= $re; break;
            case self::GT: $rs = $le  > $re; break;
            case self::GE: $rs = $le >= $re; break;
        }
        $msg = ($rs) ? "true" : "false";
        $nme = $this->getName();
        print "comparator $nme, $le vs $re: $msg\n";
        $this->setCaller($_caller);
        $this->setResult($rs);
        $this->chainExec();
    }
}
?>